package com.tinem.platform.service.message.observable;

import com.tinem.platform.service.message.config.MailConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author fzh
 * @version v1
 * @program: platform
 * @className EMailListener
 * @description TODO
 * @site 
 * @company 
 * @create 2020-09-28 17:55
 */
@Service
@Order(1)
public class VariableListener implements ApplicationListener<MessageObservable> {

    @Override
    public void onApplicationEvent(MessageObservable event) {
        if(!(event.getBody() instanceof String)){
            return;
        }
        String sendBody = (String) event.getBody();
        if(event.getSource().getParams() == null){
            return;
        }
        for (Map.Entry<String, String> entry : event.getSource().getParams().entrySet()){
            sendBody = sendBody.replaceAll("\\$\\{\\{"+entry.getKey()+"\\}\\}",entry.getValue());
        }
        event.setBody(sendBody);
    }
}
